package com.linwen.excise.leetcode;

/**
 * @ClassName _459重复的子字符串
 * @Description TODO
 * @Author zero
 * @DATE 2024/9/28 5:21 PM
 * @Version 1.0
 */
public class _459重复的子字符串 {
    public static void main(String[] args) {
        _459重复的子字符串 inst = new _459重复的子字符串();
        String s = "abab";
        System.out.println(inst.repeatedSubstringPattern(s));
    }
    public boolean repeatedSubstringPattern(String s) {
        for (int i = 1; i < s.length(); i++) {
            String child = s.substring(0,i);
            if(isRepeated(s,child)){
                return true;
            }
        }
        return false;
    }
    private boolean isRepeated(String s, String child) {
        if (s.length() % child.length() == 0) {
            for (int i = 0; i < s.length() / child.length(); i++) {
                for (int j = 0; j < child.length(); j++) {
                    if (child.charAt(j) != s.charAt(i * child.length() + j)) {
                        return false;
                    }
                }
            }
            return true;
        }
        return false;
    }
}
